package com.zhongke.cotrun.mapper;

import com.zhongke.cotrun.model.pojo.UserAllIntegral;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface UserAllIntegralMapper {
    /**
     * 新增账户
     *
     * @param userAllIntegral
     * @return
     */
    @Insert("INSERT INTO `user_all_integral` (`all_value`, `user_id`, `update_time`, `create_time`,`expiration_time`) VALUES (#{allValue}, #{userId}, NOW(), NOW(),DATE_ADD(NOW(), INTERVAL 2 YEAR))")
    public boolean insertUserAlllntegralMapper(UserAllIntegral userAllIntegral);

    /**
     * 跟新账户的值(根据用户的id值)
     *
     * @param allValue
     * @param userId
     * @return
     */

    @Update("UPDATE `user_all_integral` SET `all_value`=#{allValue}, `update_time`=NOW() WHERE (`user_id`=#{userId})")

    public boolean updateUserAllIntegral(BigDecimal allValue, Integer userId);

    /**
     * 根据用户的id查看用户的账号
     *
     * @param userId
     * @return
     */
    @Select("SELECT * FROM user_all_integral WHERE user_id=#{userId} ORDER BY create_time ASC")
    public List<UserAllIntegral> selectUserAllIntegral(Integer userId);

    /**
     * 根据用户id获取账号的值
     *
     * @param userId
     * @return
     */
    @Select("SELECT SUM(all_value) from user_all_integral WHERE user_id=#{userId}")
    public BigDecimal selectUserAllIntegralValueByUserId(Integer userId);

    /**
     * 根据id删除账户
     * @param userId
     * @return
     */
    @Delete("DELETE FROM user_all_integral WHERE all_integral_id=#{ userId}")
    public Boolean delectThisUserAllIntegral(Long userId);

}
